package greedyAlgorithm;

import java.util.Arrays;

public class triangleNumber {
    public static int triangleNumber(int[] nums) {
        int cur=nums.length-1;
        int left=0,right=nums.length-2;
        int ret=0;
        Arrays.sort(nums);
        for(cur=nums.length-1;cur>=2;cur--){
            left=0; right=cur-1;
            while(left<right){
                if(nums[left]+nums[right]>nums[cur]){
                    ret+=right-left;
                    right--;
                }else{
                    left++;
                }
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        int array[]={4,2,3,4};
        System.out.println(triangleNumber(array));
    }
}
